package com.example.demofin.controller;

import com.example.demofin.pojo.user;
import com.example.demofin.response.Response;
import com.example.demofin.response.ResponseResult;
import com.example.demofin.serveice.impl.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//最后都调用createOkResp来返回数据。失败就直接throw抛出写错误信息
@RestController
@RequestMapping("/result")
public class Resultcontoller {

    @Autowired
    private UsersService serviceme;

    //查询书写格式
    @GetMapping("/selectall")
    public ResponseResult<List<user>> selectall(){
        List<user> userList=  serviceme.selectUsers();
        return Response.createOkResp(userList);
    }


//    @PutMapping("/updateshucan")
//    @ResponseBody
//    public  ResponseResult<List<user>> updateuser_shucan(@RequestBody Map map){
//        serviceme.updateuserbyid_shucan(map);
//        return Response.createOkResp(serviceme.selectUsers());
//
//    }

   //更新书写格式以这条为准
    @PostMapping("/updateshucan2")
    @ResponseBody
    public ResponseResult<List<user>> updateuser_shucan2(@RequestBody Map map)
    {
        try {
            serviceme.updateuserbyid_shucan(map);

            return Response.createOkResp(serviceme.selectUsers());
        }
        catch (Exception e){
            throw new IllegalStateException("错误：修改失败，其他错误");
//            return Response.createFailResp("添加失败");
        }
    }
}
